package com.xtwy.admin.web.config.shiro;

import lombok.Data;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 类的描述：
 * 继承shiro UsernamePasswordToken
 *
 * @作者: 侯建军
 * @邮箱: 474177818@qq.com
 * @博客: https://blog.csdn.net/marquis888
 * @创建日期: 2018年11月18日  12:26
 * @版本: v1.0
 * @jdk版本使用: JDK1.8
 */
@Log
@Slf4j
@Data
public class CustomerAuthenticationToken extends UsernamePasswordToken {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String captcha;
    /**
     * 用来区分前后台登录的标记
     */
    private String loginType;
    /**
     * 用来区分登录用户的渠道
     */
    private String loginForm;

    private String token;

    public CustomerAuthenticationToken(String username, String password, boolean rememberMe) {
        super(username, password, rememberMe);
    }

    public CustomerAuthenticationToken(String token, String loginType){
        this.token = token;
        this.loginType = loginType;
    }

    @Override
    public Object getPrincipal() {
        if(this.token != null){
            return this.token;
        }else{
            return this.getUsername();
        }
    }

    @Override
    public Object getCredentials() {
        if(this.token != null){
            return this.token;
        }else{
            return this.getPassword();
        }
    }
}
